public class test9 {
        public static void main(String[] args) {
            Thread thread = new Thread(() -> {
                try {
                    // 线程休眠一段时间
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            });

            // 输出线程初始状态
            System.out.println("初始状态: " + thread.getState());

            // 启动线程
            thread.start();

            // 主线程循环检查子线程状态
            while (thread.getState()!= Thread.State.TERMINATED) {
                try {
                    // 主线程休眠一段时间，避免过度占用CPU
                    Thread.sleep(200);
                    System.out.println("当前状态: " + thread.getState());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

            // 输出线程终止状态
            System.out.println("终止状态: " + thread.getState());
        }

}
